# 编译器设置
CXX = g++
CXXFLAGS =  -std=c++11 -I./include

# 链接选项
LDFLAGS = -lncurses -lmenu -lpanel -lform 

# 源文件目录和目标文件目录
SRC_DIR = src
OBJ_DIR = obj

# 源文件和目标文件
SRCS = $(wildcard $(SRC_DIR)/*.cpp)
OBJS = $(SRCS:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)

# 可执行文件名
TARGET = student-tui-tool

# 默认目标
all: $(OBJ_DIR) $(TARGET)

# 安装路径
INSTALL_DIR = /usr/local/bin

# 创建目标文件目录
$(OBJ_DIR):
	mkdir -p $(OBJ_DIR)

# 链接目标文件生成可执行文件
$(TARGET): $(OBJS)
	$(CXX) $(OBJS) -o $@ $(LDFLAGS)

# 编译源文件生成目标文件
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@

# 清理目标
.PHONY: clean
clean:
	rm -rf $(OBJ_DIR) $(TARGET)

# 重新构建
.PHONY: rebuild
rebuild: clean all

#安装目标
.PHONY: install
install: $(TARGET)
	@if [ $$(id -u) -ne 0 ]; then \
		echo "please use sudo make install"; \
		exit 1; \
	fi
	install -m 755 $(TARGET) $(INSTALL_DIR)
	@echo "install ok"

# 卸载目标
.PHONY: uninstall
uninstall:
	@if [ $$(id -u) -ne 0 ]; then \
		echo "please use sudo make uninstall"; \
		exit 1; \
	fi
	rm -f $(INSTALL_DIR)/$(TARGET)
	@echo "uninstall ok"